<template>
	<view class="page">
		<u-tabs ref="tabs" name="value" :current="tabsCurrent" :list="list" @change="tabsChange"></u-tabs>
		<!-- 查询 -->
		<search placeholder="询价单编号" ref="search" @search="search()"></search>
		<u-card :show-head="false" padding="10" :border="false" margin="20rpx 0" border-radius="0"
			:foot-border-top="false" v-for="(item,index) in inquiryList" :key="index" @click="view(item.id)">
			<view class="" slot="body">
				<view class="u-body-item">
					<view class="item">
						<view class="title">询价单编号:</view>
						<view class="info">{{item.fagrmntid044}}</view>
					</view>
				</view>
				<view class="u-body-item">
					<view class="item">
						<view class="title">询价描述:</view>
						<view class="info">{{item.fagrmntid044Text}}</view>
					</view>
				</view>
				<view class="u-body-item">
					<view class="item">
						<view class="title">询价有效期:</view>
						<view class="info">{{ `${item.rfqStart || "-"} 至 ${item.rfqEnd || "-"}` }}</view>
					</view>
				</view>
<!-- 				<view class="u-body-item">
					<view class="item">
						<view class="title">币别:</view>
						<view class="info">{{item.docCurrency}}</view>
					</view>
				</view> -->
				<view class="u-body-item">
					<view class="item">
						<view class="title">货运协议有效期:</view>
						<view class="info">{{ `${item.validityStartTs || "-"} 至 ${item.validityEndTs || "-"}` }}</view>
					</view>
				</view>
				<view class="u-body-item">
					<view class="item">
						<view class="title">询价响应截止日期:</view>
						<view class="info">{{item.responseEnd}}</view>
					</view>
				</view>
			</view>
			<view class="u-footer" slot="foot">
				<u-button type="primary" @click="view(item.id)" :custom-style="customStyle" plain size="medium">
					详情
				</u-button>
			</view>
		</u-card>
		<u-loadmore :status="loadmoreStatus" :load-text="loadText" @loadmore="clickLoadmore" />
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import Search from '../../components/Search.vue';
	export default {
		data() {
			return {
				list: [{
					"key": "already",
					"value": "待报价"
				}, {
					"key": "loaded",
					"value": "待接受"
				}, {
					"key": "arriveAtTheTransferStation",
					"value": "待确认"
				}, {
					"key": "finish",
					"value": "已完成"
				}, {
					"key": "arrived",
					"value": "已作废"
				}],
				inquiryList: [],
				searchId: '',
				tabsCurrent: 0,
				current: 1, //当前页
				size: 10, //每页数量
				loadmoreStatus: 'loadmore',
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '正在加载',
					nomore: '没有更多了'
				},
				customStyle: {
					marginLeft: '20rpx',
				},
			}
		},
		components: {
			Search,
		},
		onShow() {
			this.size = 10
			this.current = 1
			this.inquiryList = []
			this.searchId = ""
			this.$refs.search.reset()
			this.getList()
		},
		//下拉刷新
		onPullDownRefresh() {
			this.size = 10
			this.current = 1
			this.inquiryList = []
			this.searchId = ""
			this.$refs.search.reset()
			this.getList()
			uni.stopPullDownRefresh();

		},
		//上拉加载
		onReachBottom() {
			if (this.size === 10) {
				this.current += 1
				this.getList()
			} else {
				this.loadmoreStatus = 'nomore'
			}
		},
		methods: {
			//切换
			tabsChange(index) {
				this.tabsCurrent = index
				this.size = 10
				this.current = 1
				this.inquiryList = []
				this.searchId = ""
				this.$refs.search.reset()
				this.getList()
			},
			//点击加在更多
			clickLoadmore() {
				if (this.size === 10) {
					this.current += 1
					this.getList()
				} else {
					this.loadmoreStatus = 'nomore'
				}
			},
			//获取数据列表
			getList() {
				this.loadmoreStatus = 'loading'
				this.$u.api.carrier.getInquiryorder({
					current: this.current,
					size: this.size,
					demandStatus: this.list[this.tabsCurrent].key,
					fagrmntid044: this.searchId
				}).then(data => {
					if (data.code === 200 && data.success) {
						this.size = data.data.records.length
						if (this.size < 10) {
							this.loadmoreStatus = 'nomore'
						} else {
							this.loadmoreStatus = 'loadmore'
						}
						this.inquiryList = this.inquiryList.concat(data.data.records)
					}
				}).catch(() => {
					this.loadmoreStatus = 'loadmore'
				})
			},
			// 查询
			search(val) {
				this.current = 1
				this.size = 10
				this.inquiryList = []
				this.searchId = val || ""
				this.getList()
			},
			//详情
			view(id) {
				uni.navigateTo({
					url: `./inquiryDetail?id=${id}`
				})
			},
		}
	}
</script>

<style lang="less">
	.page {
		min-height: 100vh;
		width: 750rpx;
		background-color: #f9f9f9;

		.u-body-item {
			font-size: 28rpx;
			color: #999999;
			width: 100%;
			padding: 0rpx 30rpx;
			box-sizing: border-box;
			margin-bottom: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.item {
				display: flex;
				justify-content: flex-start;
				align-items: flex-start;

				.title {
					width: 230rpx;
				}

				.info {
					width: 440rpx;
					color: #333333;
					word-break: break-all;
				}
			}
		}

		.u-footer {
			display: flex;
			justify-content: flex-end;
			button{
				padding: 0 40rpx;
			}
		}
	}
</style>
